<link rel="stylesheet" type="text/css" href="../stylesheet/style.css"/>
<?php
	/*
	* @author Nguyen Xuan Hong
	* @copyright 2011
	*/
	
require_once('../includes/video.tbl.php');
require_once('../includes/branch.tbl.php');
$branch_id = $_GET['branch'];

if($_GET['mode'] == 'listvideo')
{
	$pClsVideo = new clsVideoTable();
	if($pClsVideo->avaibleSubmit())
	{
		$pClsVideo->loadBuffer();
		$pClsVideo->setvalue('branch_id', $branch_id);
		
		$pClsVideo->insertDB();
		$id = $pClsVideo->value('id');
   		
		$image = upload_file("Upload/", 'imgbrowser_image', $pClsVideo->value('image'), "vip".$id);
		if($image != "")
		{
			$pClsVideo->setvalue('image', $image);
		}
		
		$url = upload_file("Upload/", 'videobrowser_url', $pClsVideo->value('url'), "vid".$id);
		if($url != "")
		{
    		$pClsVideo->setvalue('url', $url);
		} 
		
		$pClsVideo->updateDB('id',$id);
		
		echo acpredirect();
		exit();
	}
	echo $pClsVideo->createForm('Thêm video');
	
	require_once('../includes/templates.php');
	$table = new clsTable('lstintrovideo',array(array("ID", "1"),array("Tên video", 0),array("Url video", 0),array("Hiển thị video", 1),array("Sửa", 1),array("Xóa", 1)));
	$arr_introvideo = $pClsVideo->listobj($branch_id);
	foreach($arr_introvideo as $video){
		$html_remove = 	'<a href="?page=video&mode=deletevideo&branch='.$branch_id.'&id='.$video->id.'">Xóa</a>';	
		$html_edit = 	'<a href="?page=video&mode=editvideo&branch='.$branch_id.'&id='.$video->id.'">edit</a>';	 
		$table->addRow($video->value('id'),array($video->value('id'),$video->value('title'),$video->value('url'),($video->value('display'))?"Có":"Không",$html_edit,$html_remove));
	}
	echo $table->putHTML(true);
	exit();
}
	  
if($_GET['mode'] == 'deletevideo')
{
	// Redefine insert
	$deleteid = sget('id');			
	$pClsVideo = new clsVideoTable($deleteid);
	if(!$_POST['submit']){
		?>
        
	<center><div class="notification warning">
        <span></span>
        <p><strong>Warning!</strong> 
        	<div class="text">Bạn có muốn xóa video này không</div> 
            <div class="btn"><form method='post'><input type='submit' name='submit' value = 'Xóa' /></form></div>
         </p>
	</div></center>
        <?
		exit();
	}
	$pClsVideo->removeDB('id', $deleteid);
	header("location:index.php?page=video&mode=listvideo&branch=".$branch_id);
	exit();
}
	
	
if($_GET['mode'] == 'editvideo')
{
	$edit = (int)sget('id');
	$pClsVideo = new clsVideoTable($edit);
	if($pClsVideo->avaibleSubmit()){
		$pClsVideo->loadBuffer();
		$image = upload_file("Upload/", 'imgbrowser_image', $pClsVideo->value('image'), "vip".$id);
		if($image != "")
		{
			$pClsVideo->setvalue('image', $image);
		} 
		
        $url = upload_file("Upload/", 'videobrowser_url', $pClsVideo->value('url'), "vid".$id);
		if($url != "")
		{
    		$pClsVideo->setvalue('url', $url);
		}
		$pClsVideo->updateDB('id',$edit);
        echo acpredirect('page=video&mode=listvideo&branch='.$branch_id);
		exit();
	}
	$pClsVideo->loadDB('id',$edit);
	echo $pClsVideo->createForm('Sửa video');
	exit();
}
	
	
	if($_GET['mode'] == 'addvideo'){	
		// Redefine insert
		if($pClsVideo->avaibleSubmit()){
			$pClsVideo->loadBuffer();
			$pClsVideo->getvalue();
			$pClsVideo->businessid=sget('id');
			$pClsVideo->insertDB();
			echo "Đã thêm xong <meta http-equiv='refresh' content='0;url=index.php?".$_SERVER['QUERY_STRING']."'>";
			exit();
		}
		$videos->businessid=sget('id');
		echo $videos->createForm('Thêm video');
		exit();
	}
?> 














  